/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import Entity.Person;
import Services.PersonService;
import java.util.Date;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author itachiu
 */
public class PersonServiceTest {
    
    private static EntityManagerFactory emf=null;
    public PersonServiceTest() {
    }
    
    @BeforeClass
    public static void setUpClass() {
        emf=Persistence.createEntityManagerFactory("HPVASPU");
    }
    
    @AfterClass
    public static void tearDownClass() {
    }
    
    @Before
    public void setUp() {
    }
    
    @After
    public void tearDown() {
    }
    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    //
     @Test
     public void testCreate() {
        EntityManager em=emf.createEntityManager();
        PersonService ps=new PersonService(emf);
         /**initializa dates**/
        Person p=new Person();
        p.setName("carlos");
        p.setLastname("sanchez");
        p.setSSN("222-33");
        p.setBirthdate(new Date());
//        p.setId(1L);
        /**test**/
        ps.create(p);
        Person s=null;
        s=ps.findPersonEntities().get(0);
        assertEquals(p.getName(),s.getName());
     }
}
